package com.mercenary.wein.screenControl.service;

import com.mercenary.wein.screenControl.bean.DeviceBean;
import com.mercenary.wein.screenControl.bean.GroupMetaBean;
import com.mercenary.wein.screenControl.bean.CommandBean;
import com.mercenary.wein.screenControl.dao.GroupDao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.List;

/**
 * Created by tuxiao on 2017/3/12.
 */
public class GroupService {
    Log log = LogFactory.getLog(GroupService.class);
    static GroupDao groupDao = new GroupDao();
    public void sendCommondByGId(int groupId,CommandBean command){
        log.info("send command:["+command+"] to group ["+groupId+"]");
        List<DeviceBean> devices = groupId==0? groupDao.findDevicesGroups(): groupDao.findDevicesByGroupId(groupId);
//        CommandPool.sendCommand(devices,command);
    }

    public GroupMetaBean addGroup(String gname){
        return groupDao.createGroupMeta(gname,"");
    }

    public List<GroupMetaBean> getAllGroupMetaBean(){
        return groupDao.getGroups();
    }

    public List<DeviceBean> getDevicesByGid(long gid){
        if(gid==0){//选择全部手机的情况
            return groupDao.findDevicesGroups();
        }
        return groupDao.findDevicesByGroupId(gid);
    }

    public String getGroupName(long gcode){
        if(groupDao.getGroupName(gcode)==null)return "未知分组";
        else return groupDao.getGroupName(gcode);
    }

    public void updateDeviceGroup(long gcode, String serialNo){
        groupDao.updateDeviceGroup(gcode,serialNo);
    }
}
